package Test;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.Scanner;

public class A1 {
    public static void main(String[] args) throws IOException {
        // 首先要有一个目标，向哪一个服务端发送消息
        InetSocketAddress severIP = new InetSocketAddress("127.0.0.1", 8888);
        // 有了目标主机后，就可以建立连接
        Socket socket = new Socket();
        socket.connect(severIP);
        // 已经连接上了，就可以发送数据，利用IO流

        OutputStream os = socket.getOutputStream();
        PrintStream ps = new PrintStream(os);    // 发文字消息用打印流更方便
        Scanner in = new Scanner(System.in);
        while (true) {
            System.out.println("请输入消息:");
            ps.println(in.nextLine());
            ps.flush();
        }
    }

}
